package com.briup.app08.web.controller;

import com.briup.app08.bean.UserInfo;
import com.briup.app08.service.IUserInfoService;
import com.briup.app08.utils.Message;
import com.briup.app08.utils.MessageUtil;
import com.sun.istack.internal.NotNull;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
@RequestMapping("/userinfo")
public class UserInfoController {
    @Resource
    private IUserInfoService userInfoService;

    @GetMapping("query")
    public Message query(String realname,String gender){
        List<UserInfo> list =  userInfoService.query(realname,gender);
        return MessageUtil.success(list);
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(UserInfo info){
        userInfoService.saveorupdate(info);
        return MessageUtil.success("操作成功");
    }

    @DeleteMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户编号", required = true, paramType = "query"),
    })
    public Message deleteById(@NotNull Long id){
        userInfoService.deleteById(id);
        return MessageUtil.success("操作成功");
    }
}
